<template>
  <view class="container">
    <view class="main">
      <div class="form">
        <input type="text" class="input" v-model="name" placeholder="任务名称" />
        <picker
          class="picker"
          @change="bindPickerChange"
          :value="index"
          :range="array"
        >
          <view class="input"> 任务时间: {{ array[index] }}分钟 </view>
        </picker>
        <view class="title-2">
          最多选择三种。（{{ selectedNum }} / {{ 3 }}）
        </view>
        <tag-cloud :tagnames="tagnames" :selected.sync="selected" />
        <button class="button" @click="handlerBtnClick" plain type="primary">
          我选好了
        </button>
      </div>
    </view>
  </view>
</template>

<script>
import TagCloud from "../../components/TagCloud";
export default {
  name: "clock-profile",
  data() {
    return {
      name: '',
      array: [1, 5, 10, 15, 30, 45, 60],
      index: 0,
      selected: [],
      tagnames: [
        "学习",
        "运动",
        "暴打张一铭",
        "暴打赵浪",
        "抄编译原理作业",
      ],
      selectedNum: 0,

    };
  },
  components: {
    TagCloud,
  },
  watch: {
    selected() {
      this.selectedNum = this.selected.length;
    },
  },
  methods: {
    bindPickerChange(e) {
      this.index = e.detail.value;
    },
    handlerBtnClick() {
      this.$emit('submit', {
        tag: this.selected,
        name: this.name,
        target: this.array[this.index],
      })
    }
  },
};
</script>

<style scoped>
.title-2 {
  margin-top: 32rpx;
}
.button {
  width: 100%;
  margin-top: 64px;
}
.container {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.container > .main {
  width: 80%;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.form {
  width: 100%;
  display: flex;
  flex-direction: column;
  margin-top: 64rpx;
  align-items: center;
}
.form .picker {
  width: 100%;
}
.form .input {
  width: 100%;
  border: none;
  border-bottom: 1px solid black;
  box-sizing: border-box;
  margin-top: 64rpx;
  font-size: 42rpx;
  line-height: 64rpx;
  height: 64rpx;
}
</style>